﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StuertzDatenbank;

namespace StuertzDatenbank

{
    public partial class AlleProfilgui : Form
    {
        private Sprachfile sprachfile;
        private DBF dbf;
        private List<Profil> profilListe;

        public AlleProfilgui(Benutzer benutzer)
        {
            this.benutzer = benutzer;
            InitializeComponent();
            sprachfile = new Sprachfile();
            dbf = new DBF();
            profilListe = new List<Profil>();
          
            InitializeComponentChange();
            this.Refresh();
        }

        private void InitializeComponentChange()
        {
            this.Text = sprachfile.AlleProfile;
            this.Text = sprachfile.AlleProfile;
            this.Start.Text = sprachfile.Start;
            this.Suchen.Text = sprachfile.Suche;
            this.SucheTextbox.Text = "";
            this.Bearbeienbutton.Text = sprachfile.Bearbeiten;

          
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Start_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            startgui gui = new startgui(benutzer);
            this.Dispose();
            gui.ShowDialog();
        }

        public Benutzer benutzer { get; set; }

        private void Zurück_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            ProfilstartGui gui = new ProfilstartGui(benutzer);
            this.Dispose();
            gui.ShowDialog();
            
        }

        private void Suchen_Click(object sender, EventArgs e)
        {
            this.dataGridView1.Rows.Clear();
            if (SucheTextbox.Text=="")
            {
                profilListe = dbf.getAllProfile();
            }
            else
            {
               profilListe= dbf.getProfilesByName(this.SucheTextbox.Text);
            }


            Datagridfüllen();
        }

        private void Datagridfüllen()
        {
            //Liste Füllen
            for (int i = 0; i < profilListe.Count; i++)
            {
                this.dataGridView1.Rows.Add(profilListe[i].getID(), profilListe[i].getBezeichnung());
            }
        }

        private void Bearbeienbutton_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count>0)
            {
                Profilgui gui = new Profilgui(this.benutzer, dbf.ProfilAusgeben(int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString())));

                this.Dispose();
                gui.ShowDialog();

               
            }
            else
            {
                MessageBox.Show(sprachfile.Bittezuerstauswaehlen);
            }
         
        
        }

        private void dataGridView1_DoubleClick(object sender, System.EventArgs e)
        {
            Bearbeienbutton_Click(sender, e);
        }


    }
}
